/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 10:14:50
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2023-08-18 14:19:38
 */
import { getAreaObj } from '@/utils/util'
import {EncodeUtf8,revertUTF8} from '@/views/oneStopOffice/utils/index'
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '来源单位区划', prop: 'areasName' },
		{ label: '标题', prop: 'infoTitle' },
		{
			label: '来源层级',
			prop: 'fromLevel',
			propName: 'fromLevelLabel',
			type: 'remoteSelect',
			code: 'POLICY_LEVEL',
			api: 'getDictItemList',
		},
		{
			label:"分类",
			prop:"infoCategory",
			custome:'tag',
			code: 'OLD_MAN_INFO_CATEGORY',
		},
		{
			label:'发布人',
			prop:'publisher'
		},
		{ label: '发布日期', prop: 'publishDate' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

// 新增编辑
export const BaseFormConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		
		{
			label: '标题',
			prop: 'infoTitle',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入标题' }],
		},
		{
			label:'发布人',
			prop:'publisher',
			span:12,
			rules: [{ required: true, message: '请输入发布人' }],
		},
		{
			label: '关键词',
			prop: 'infoKeywords',
			filterable: true,
			allowCreate: true,
			multiple: true,
			type: 'select',
			span: 24,
		},
		{
			label: '是否顶置',
			prop: 'pushTop',
			propName:'pushTopLabel',
			dicData:[
				{label:"否",value:"0",type:"danger"},
				{label:"是",value:"1",type:"success"},
			],
			type: 'select',
			rules: [{ required: true, message: '请选择是否顶置' }],
			span: 8,
		},
		{
			label: '来源单位',
			prop: 'fromName',
			maxlength: '100',
			type: 'input',
			span: 8,
			rules: [{ required: true, message: '请输入来源单位' }],
		},
		{
			label: '分类',
			prop: 'infoCategory',
			propName:'infoCategoryLabel',
			code:'OLD_MAN_INFO_CATEGORY',
			api:'getDictItemList',
			type: 'remoteSelect',
			multiple:false,
			span: 8,
		},
		{
			label: '来源层级',
			prop: 'fromLevel',
			propName: 'fromLevelLabel',
			type: 'remoteSelect',
			code: 'POLICY_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请选择来源层级' }],
		},
		
		{
			label: '来源单位区划',
			prop: 'areas',
			propName: 'areasName',
			regionGrade: 3,
			checkStrictly: false,
			type: 'AplidAreaSelect',
			rules: [{ required: true, message: '请选择来源单位区划' }],
			span: 8,
		},
		// {
		// 	label: '文章摘要',
		// 	prop: 'infoAbstract',
		// 	type: 'input',
		// 	span: 8,
		// },
		
		{
			label: '发布日期',
			prop: 'publishDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请输入发布日期' }],
		},
		{
			label: '上传资讯图片、视频',
			prop: 'infoImg',
			type: 'upload',
			fileType:'image/jpeg,video/mp4,image/jpg,image/png,video/m3u8',
			listType:'picture',
			// uploadTip:'上传视频',
			labelPosition: 'left',
			fileSize:100,
			apiName:"ost_uploadFile2",
			// showFileList: true,
			limit: 9,
			multiple: false,
			span: 24,
		},
		{
			label: '内容',
			prop: 'infoContent',
			showWordLimit: true,
			type: 'ueditor',
			height: '20rem',
			span: 24,
			rules: [{ required: true, message: '请输入内容' }],
		},
	],
}

export const detailConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		{
			custome: 'HtmlLabel',
			prop: 'infoTitle',
			flag: 'bgTitle',
			labelPosition: 'top',
			span: 24,
		},
		{
			label: '标题',
			prop: 'infoTitle',
			type: 'input',
			labelPosition: 'left',
			span: 8,
			rules: [{ required: true, message: '请输入标题' }],
		},
		{
			label:'发布人',
			prop:'publisher',
			labelPosition: 'left',
			span:8
		},
		{
			label: '关键词',
			prop: 'infoKeywords',
			filterable: true,
			allowCreate: true,
			multiple: true,
			labelPosition: 'left',
			type: 'select',
			span: 8,
		},
		{
			label: '是否顶置',
			prop: 'pushTop',
			custome:"tag",
			code:'COMMON_FLAG',
			span: 8,
		},
		{
			label: '来源单位',
			prop: 'fromName',
			maxlength: '100',
			type: 'input',
			labelPosition: 'left',
			span: 8,
			rules: [{ required: true, message: '请输入来源单位' }],
		},
		{
			label: '分类',
			prop: 'infoCategory',
			code:'OLD_MAN_INFO_CATEGORY',
			api:'getDictItemList',
			type: 'remoteSelect',
			multiple:false,
			span: 8,
		},
		{
			label: '来源层级',
			prop: 'fromLevel',
			propName: 'fromLevelLabel',
			type: 'remoteSelect',
			code: 'POLICY_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			labelPosition: 'left',
			span: 8,
			rules: [{ required: true, message: '请选择来源层级' }],
		},
		
		{
			label: '来源单位区划',
			prop: 'areas',
			propName: 'areasName',
			regionGrade: 3,
			checkStrictly: false,
			type: 'AplidAreaSelect',
			labelPosition: 'left',
			rules: [{ required: true, message: '请选择来源单位区划' }],
			span: 8,
		},
		// {
		// 	label: '文章摘要',
		// 	prop: 'infoAbstract',
		// 	type: 'input',
		// 	span: 8,
		// },
		
		{
			label: '发布日期',
			prop: 'publishDate',
			type: 'date',
			labelPosition: 'left',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			type: 'DividerHtml',
			custome: 'divider',
			position: 'center',
			labelPosition: 'top',
			modelValue: '',
			span: 24,
		},
		{
			prop: 'infoImg',
			span: 4,
			custome: 'carousel',
			labelPosition: 'top',
			width: '376px',
			style: {
				width: '376px',
				height: '300px',
				borderRadius: '20px 0',
				padding: '10px',
			},
			children: [
				{
					label: '内容',
					prop: 'infoContent',
					showWordLimit: true,
					maxlength: '1000',
					type: 'ueditor',
					height: '20rem',
					labelPosition: 'top',
					span: 24,
				},
			],
		},
	],
}

const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共2个：',
					children: [
						{
							label: '《养老资讯数据管理信息表》',
							link: true,
							url: 'dpNewsInfo_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入《养老资讯数据管理信息表》',
			description: '',
			uploadTip: '养老资讯数据管理信息表',
			active: 2,
			url: 'dpNewsInfo_import',
			code: 3005,
			rules: [
				{
					label: '导入规则说明:',
					children: [
						{
							label: '(1)导入模式为“覆盖导入”，待导入的养老资讯数据管理信息会覆盖平台已存在的',
						},
					],
				},
			],
		},
	],
}
export const baseConfig = {
	pageName: '养老资讯文件管理',
	// 数据字典
	dictcodes: ['COMMON_FLAG', 'POLICY_LEVEL', 'POLICY_TAGS', 'OLDMAN_TYPE', 'SUBSIDY_TYPE','OLD_MAN_INFO_CATEGORY'],
	rowKey: 'id',
	addLabel: '新增',
	// 删除插入
	tipLabel: 'infoTitle',
	exportMqTopic: '/ning/export/',
	api: {
		index: 'dpNewsInfo_page',
		// export: 'dpNewsInfo_export',
		delete: 'dpNewsInfo_del',
		add: 'view_dpNewsInfo_gather',
		edit: 'dpNewsInfo_edit',
		// import: 'dpNewsInfo_import',
	},
	
	auth: {
		index: 'view_dpNewsInfo_page',
		// export: 'view_dpNewsInfo_export',
		delete: 'view_dpNewsInfo_del',
		add: 'view_dpNewsInfo_gather',
		edit: 'view_dpNewsInfo_edit',
		// import: 'view_dpNewsInfo_import',
		// 批量搜索
		mulitSet: 'mulitSet',
	},
	// 当前行操作按钮
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'Detail',
			auth: 'view_dpNewsInfo_view',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'Edit',
			auth: 'view_dpNewsInfo_edit',
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: 'view_dpNewsInfo_del',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '85%',
	},
	detailConfig:detailConfig,
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '来源单位',
				prop: 'fromName',
				type: 'input',
				span: 6,
			},
			{
				label: '分类',
				prop: 'infoCategory',
				propName:'infoCategoryLabel',
				code:'OLD_MAN_INFO_CATEGORY',
				api:'getDictItemList',
				type: 'remoteSelect',
				multiple:false,
				span: 6,
			},
			{
				label: '标题',
				prop: 'infoTitle',
				type: 'input',
				span: 6,
			},
			{
				label: '关键词',
				prop: 'infoKeywords',
				type: 'input',
				span: 6,
			},
			{
				label: '来源层级',
				prop: 'fromLevel',
				propName: 'fromLevelLabel',
				type: 'remoteSelect',
				code: 'POLICY_LEVEL',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
			{
				label: '发布日期',
				prop: 'publishDateBetween',
				type: 'daterange',
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
			},
		],
	},
	// 新增
	formConfig: {
		...BaseFormConfig,
		showBtn: true,
	},
	// 列表
	tableConfig,
	importConfig,
	// 处理发布日期
	beforeOnLoadFormate: async (params) => {
		if (params.publishDateBetween) {
			params.publishDateBetween = params.publishDateBetween.join(',')
		}
		return Promise.resolve({
			...params,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areasInfo: any = getAreaObj(item, 'from', 'set')
			if(item.infoKeywords){
				item.infoKeywords = item.infoKeywords.split(',')
			}
			if(item.infoContent){
				item.infoContent = revertUTF8(item.infoContent)
				
			}
			// 输入框都进行一下解密
			BaseFormConfig.column.forEach(el=>{
				if((!el.type||el.type=='input'||el.type=="text")&& item[el.prop]){
				  item[el.prop] =  revertUTF8(item[el.prop])
				}
			})
			return {
				...item,
				areas: areasInfo.areaIds,
				areasName: areasInfo.names,
			}
		})
		return Promise.resolve(tableData)
	},
	// 新增处理
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, 'from')
			const areasNameObj: any = getAreaObj(form.areasName, 'from')
			if(form.infoKeywords){
				form.infoKeywords = form.infoKeywords.join(',')
			}
			if(form.infoContent){
				form.infoContent = EncodeUtf8(form.infoContent)
			}
			const params = {
				...form,
				// moduleLabel:'一站办',
				...areasObj,
				...areasNameObj,
				areas: undefined,
				areasName: undefined,
				code: 3005,
			}
			resolve(params)
		})
	},
}
